package com.example.dryyzx.dao;

import com.example.dryyzx.entity.Food;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface FoodMapper {
    @Delete({
        "delete from food",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into food (id, name, ",
        "price, type, tag, ",
        "day, halal, time, ",
        "image)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{price,jdbcType=INTEGER}, #{type,jdbcType=CHAR}, #{tag,jdbcType=VARCHAR}, ",
        "#{day,jdbcType=CHAR}, #{halal,jdbcType=BIT}, #{time,jdbcType=CHAR}, ",
        "#{image,jdbcType=LONGVARBINARY})"
    })
    int insert(Food record);

    @InsertProvider(type=FoodSqlProvider.class, method="insertSelective")
    int insertSelective(Food record);

    @Select({
        "select",
        "id, name, price, type, tag, day, halal, time, image",
        "from food",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.INTEGER),
        @Result(column="type", property="type", jdbcType=JdbcType.CHAR),
        @Result(column="tag", property="tag", jdbcType=JdbcType.VARCHAR),
        @Result(column="day", property="day", jdbcType=JdbcType.CHAR),
        @Result(column="halal", property="halal", jdbcType=JdbcType.BIT),
        @Result(column="time", property="time", jdbcType=JdbcType.CHAR),
        @Result(column="image", property="image", jdbcType=JdbcType.LONGVARBINARY)
    })
    Food selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, name, price, type, tag, day, halal, time, image",
            "from food",
            "where day = #{arg0,jdbcType=INTEGER} and time = #{arg1,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="price", property="price", jdbcType=JdbcType.INTEGER),
            @Result(column="type", property="type", jdbcType=JdbcType.CHAR),
            @Result(column="tag", property="tag", jdbcType=JdbcType.VARCHAR),
            @Result(column="day", property="day", jdbcType=JdbcType.CHAR),
            @Result(column="halal", property="halal", jdbcType=JdbcType.BIT),
            @Result(column="time", property="time", jdbcType=JdbcType.CHAR),
            @Result(column="image", property="image", jdbcType=JdbcType.LONGVARBINARY)
    })
    List<Food> selectByDayTime(String arg0, String arg1);

    @UpdateProvider(type=FoodSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Food record);

    @Update({
        "update food",
        "set name = #{name,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=INTEGER},",
          "type = #{type,jdbcType=CHAR},",
          "tag = #{tag,jdbcType=VARCHAR},",
          "day = #{day,jdbcType=CHAR},",
          "halal = #{halal,jdbcType=BIT},",
          "time = #{time,jdbcType=CHAR},",
          "image = #{image,jdbcType=LONGVARBINARY}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(Food record);

    @Update({
        "update food",
        "set name = #{name,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=INTEGER},",
          "type = #{type,jdbcType=CHAR},",
          "tag = #{tag,jdbcType=VARCHAR},",
          "day = #{day,jdbcType=CHAR},",
          "halal = #{halal,jdbcType=BIT},",
          "time = #{time,jdbcType=CHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Food record);
}